package com.zhou.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectById;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhou.config.Result;
import com.zhou.entity.QuestionRepo;
import com.zhou.mapper.QuestionRepoMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 题库表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2023-03-13
 */
@RestController
@RequestMapping("/question")
@Api(tags="题库表接口信息")
public class QuestionRepoController {

    @Autowired
    private QuestionRepoMapper questionrepoService;

    @Resource
    private QuestionRepoMapper questionRepoMapper ;

    private static final Integer SIZE = 6;


     @ApiOperation(value = "返回题库名字")
     @GetMapping("/findRepoName")
     public List<String> findRepo(){
        return questionRepoMapper.findRepoName();
     }

    //增加一条完整的记录
    @ApiOperation(value="增加一条完整的题库表的记录")
    @RequestMapping(value = "/addQuestion",method = RequestMethod.PUT)
    public  int add(@RequestParam(name="repo_id") int repo_id,
                @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                @RequestParam(name = "create_time") LocalDateTime create_time,
                @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                @RequestParam(name = "update_time")LocalDateTime update_time
                ){
            QuestionRepo questionRepo = new QuestionRepo();
            questionRepo.setRepoId(repo_id);
            questionRepo.setUpdateTime(update_time);
            questionRepo.setCreateTime(create_time);
            return this.questionRepoMapper.insert(questionRepo);
        }

        //修改记录信息
        @ApiOperation(value="根据repo_id修改记录信息")
        @PostMapping(value= "/updateRepo")
        public int update(@RequestParam(value = "repo_id") int repo_id,
                          @RequestParam(value="repo_name") String repo_name,
                          @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                            @RequestParam(name="update_time")LocalDateTime update_time){
            QuestionRepo questionRepo = new QuestionRepo();
            questionRepo.setRepoId(repo_id);
            questionRepo.setRepoName(repo_name);
            questionRepo.setUpdateTime(update_time);
            return this.questionRepoMapper.updateById(questionRepo);}
}









